
#ifndef _TW_VECTOR2D_MathLib_H_
#define _TW_VECTOR2D_MathLib_H_
#pragma once

class TwVector2d : public D3DXVECTOR2
{
public:
	//--------------------------------------------------
	// Creators...
	//--------------------------------------------------

	TwVector2d(){};
	TwVector2d(const TwVector2d& vec):D3DXVECTOR2(vec.x,vec.y){};
	TwVector2d(const D3DXVECTOR2& vec):D3DXVECTOR2(vec.x,vec.y){};
	TwVector2d(float _x, float _y):D3DXVECTOR2(_x,_y){};
	~TwVector2d(void){};

	//--------------------------------------------------
	// Operators...
	//--------------------------------------------------

	const TwVector2d& operator *= (const TwVector2d& vec);
	const TwVector2d& operator /= (const TwVector2d& vec);
	const TwVector2d& operator *= (float v);
	const TwVector2d& operator /= (float v);

	//--------------------------------------------------
	// Mutators...
	//--------------------------------------------------

	void clear(void);
	void setToAbsoluteValue();
	void set(float _x, float _y);
	void invert();
	void negate();

	//--------------------------------------------------
	// Calculations\Operations...
	//--------------------------------------------------

	// testing operations
	float maxValue()const;
	float minValue()const;
	bool isClear()const;

	// length and distance calculations
	void normalize();
	float length()const;
	float lengthSquared()const;
	float distance(const TwVector2d& vec)const;
	float distanceSquared(const TwVector2d& vec)const;

	// dot product
	float dotProduct(const TwVector2d& vec)const;

	// reflect against the normal of a plane
	void reflect(const TwVector2d& normal);
	void reflect(const TwVector2d& source, const TwVector2d& normal);

	// refract through the normal of a plane
	void refract(const TwVector2d& normal, float incident, float transmitted);
	void refract(const TwVector2d& source, const TwVector2d& normal, float incident, float transmitted);

	// project along a normal vector
	void project(const TwVector2d& normal);
	void project(const TwVector2d& source, const TwVector2d& normal);

	// linear interpretation (float scale from 0-1)
	void twlerp(const TwVector2d& source_b, float scale);
	void twlerp(const TwVector2d& source_a, const TwVector2d& source_b, float scale);

	// test whether the vector is in the positive half-space of a normal
	bool testPositiveHalfSpace(const TwVector2d& normal)const;

	// compare with another vector using an optional epsilon value
	bool comparePosition(const TwVector2d& source)const;
	bool comparePosition(const TwVector2d& source, float epsilon)const;
	bool compareLength(const TwVector2d& source)const;
	bool compareLength(const TwVector2d& source, float epsilon)const;
	bool compareDirection(const TwVector2d& source)const;
	bool compareDirection(const TwVector2d& source, float epsilon)const;
	bool compareToZero()const;
	bool compareToZero(float epsilon)const;

	// set to the lesser components of two inputs
	void setMinByValue(const TwVector2d& source_b);
	void setMinByValue(const TwVector2d& source_a, const TwVector2d& source_b);
	// set to the lesser of two inputs (using length)
	void setMinByLength(const TwVector2d& source_b);
	void setMinByLength(const TwVector2d& source_a, const TwVector2d& source_b);

	// set to the greater components of two inputs
	void setMaxByValue(const TwVector2d& source_b);
	void setMaxByValue(const TwVector2d& source_a, const TwVector2d& source_b);
	// set to the greater of two inputs (using length)
	void setMaxByLength(const TwVector2d& source_b);
	void setMaxByLength(const TwVector2d& source_a, const TwVector2d& source_b);

};
#endif